package cn.wh.common.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.alibaba.fastjson.JSONObject;


public class BaseAction
{

	// request
	protected HttpServletRequest request =  ServletActionContext.getRequest();
	
	// response
	protected HttpServletResponse response = ServletActionContext.getResponse();
	
	// 登陆页面的提示信息
	protected String info= "";

	public String getInfo()
	{
		return info;
	}

	public void setInfo(String info)
	{
		this.info = info;
	}
	
	// 返回j-ui要求的结果
	public JSONObject juiResult (String info) throws IOException {
		
		String navTabId = request.getParameter("navTabId");
		String rel = request.getParameter("rel");
		String callbackType = request.getParameter("callbackType");
		String forwardUrl = request.getParameter("forwardUrl");
		String confirmMsg = request.getParameter("confirmMsg");
		if (navTabId == null) {
			navTabId = "";
		}
		if (rel == null) {
			rel = "";
		}
		if (callbackType == null) {
			callbackType = "";
		}
		if (forwardUrl == null) {
			forwardUrl = "";
		}
		if (confirmMsg == null) {
			confirmMsg = "";
		}
		
		JSONObject resObject = new JSONObject();
		resObject.put("statusCode", 200);
		resObject.put("message", info);
		resObject.put("navTabId", navTabId);
		resObject.put("rel", "");
		resObject.put("callbackType", callbackType);
		resObject.put("forwardUrl", forwardUrl);
		resObject.put("confirmMsg",confirmMsg);
		return resObject;
	}
	
	public void printOut(String result) throws IOException {
		PrintWriter out = response.getWriter();
		out.println(result);
		out.flush();
		out.close();
	}
	
	
}
